package com.cherrypt.api.model.bo;

import com.cherrypt.api.model.dataobject.Post;
import com.cherrypt.api.model.dto.ReleaseQualityDto;
import com.cherrypt.api.model.util.BeanUtils;
import com.cherrypt.api.model.vo.ReleaseVo;
import org.apache.commons.lang3.StringUtils;

public class ReleaseBo {
    public static Post getPostByReleaseVo(ReleaseVo releaseVo, int userId, String qualityJson) {
        Post post = new Post();
        // 处理豆瓣或imdb Id
        if (StringUtils.isNotBlank(releaseVo.getIdType())) {
            if ("imdb".equals(releaseVo.getIdType())) {
                post.setImdbId(releaseVo.getId());
            } else if ("douban".equals(releaseVo.getIdType())) {
                post.setDoubanId(releaseVo.getId());
            }
        }
        post.setUid(userId);
        post.setCategoryId(releaseVo.getCategoryId());
        post.setTitle(releaseVo.getTitle());
        post.setSubtitle(releaseVo.getSubtitle());
        post.setContent(releaseVo.getContent());
        post.setQuality(qualityJson);
        return post;
    }

    public static ReleaseQualityDto getPostQualityByReleaseVo(ReleaseVo releaseVo) {
        ReleaseQualityDto releaseQualityDto = new ReleaseQualityDto();
        BeanUtils.copyFieldToBean(releaseVo, releaseQualityDto);
        return releaseQualityDto;
    }

}
